#include <sys/types.h>
#include <wait.h>
#include <signal.h>

#include <unistd.h>

#include <stdio.h>
#include <stdlib.h>
#include <sched.h>
#include <sys/time.h>
#include <sys/resource.h>

#include <sys/types.h>

struct sched_param p[2]; //设置调度策略时使用的数据结构

typedef void (*sighandler_t) (int);
void sigmain()
{
    printf("Parent add priority\n");
    setpriority(PRIO_PROCESS,getpid(),getpriority(PRIO_PROCESS,0)+1);
}

void sigmain_nostop()
{

}

void sigsub()
{
    printf("%d Process continue\n",getpid());
    setpriority(PRIO_PROCESS,getpid(),getpriority(PRIO_PROCESS,0)+1);
}
void sigsub_nostop()
{

}

int main()
{
    int pid;

    pid = fork();


    
    if(pid > 0)
    {
	signal(SIGINT,(sighandler_t)sigmain);
	signal(SIGTSTP,(sighandler_t)sigmain_nostop);
        p[0].sched_priority = 10;
        sched_setscheduler(getpid(),SCHED_OTHER, &p[0]);    
        while(1)
        {
            printf("this is parent process,pid = %d,priority = %d,sceduler = %d\n",getpid(),getpriority(PRIO_PROCESS,0),sched_getscheduler(getpid()));
        
            sleep(1);
               
        }
    }else
    {
	signal(SIGTSTP,(sighandler_t)sigsub);
	signal(SIGINT,(sighandler_t)sigsub_nostop);
        p[1].sched_priority = 10;
        sched_setscheduler(getpid(),SCHED_OTHER, &p[1]);        
        while(1)
        {
            printf("this is child process,pid = %d,priority = %d,sceduler = %d\n",getpid(),getpriority(PRIO_PROCESS,0),sched_getscheduler(getpid()));
            sleep(1);
        }

    }
}




